package com.dormms.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dormms.bean.GoodInfo;
import com.dormms.bean.StaffInfo;
import com.dormms.dao.GoodInfoDao;
import com.dormms.dto.GoodAdmin;
import com.dormms.dto.GoodAdminInfo;
import com.dormms.service.GoodService;
@Service
public class GoodInfoServiceImpl implements GoodService{
	@Autowired
	private GoodInfoDao goodInfoDao;

	public List<GoodInfo> queryGoodInfoByGoodInfo(GoodInfo goodInfo) {
		// TODO Auto-generated method stub
		return goodInfoDao.queryGoodInfo(goodInfo);
	}

	public Integer insertGoodInfo(GoodInfo goodInfo) {
		// TODO Auto-generated method stub
		Integer goodInfoId = goodInfoDao.isGoodInfoExist(goodInfo.getGoodInfoId());
		if(goodInfoId != null) {
			return 0;
		}
		goodInfoDao.insertGoodInfo(goodInfo);
		return goodInfo.getGoodInfoId();
	}

	public Integer insertGoodAdminInfo(GoodAdmin goodAdmin) {
		// TODO Auto-generated method stub
		Integer goodInfoId = goodInfoDao.isGoodInfoExist(goodAdmin.getGoodId());
		String satffId = goodInfoDao.isGoodAdminExist(goodAdmin.getStaffId());
		if(goodInfoId!=null && !goodAdmin.getStaffId().equals(satffId)) {
			goodAdmin.setAdminStart(new Date());
			goodAdmin.setAdminStatus(1);
			goodInfoDao.insertGoodAdminInfo(goodAdmin);
			return goodAdmin.getStaffGoodId();
		}
		return 0;
	}

	public List<StaffInfo> getNoAdminGoodStaff() {
		// TODO Auto-generated method stub
		return goodInfoDao.queryNoGoodAdmin();
	}

	public GoodAdminInfo getGoodAllStaff(Integer goodInfoId) {
		// TODO Auto-generated method stub
		GoodAdminInfo goodAdminInfo = new GoodAdminInfo();
		goodAdminInfo.setGoodInfo(goodInfoDao.queryGoodInfoByGoodId(goodInfoId));
		goodAdminInfo.setStaffInfos(goodInfoDao.queryGoodAllStaffInfoByGoodId(goodInfoId));
		return goodAdminInfo;
	}

	public Integer updateGoodInfoBySuper(GoodInfo goodInfo) {
		// TODO Auto-generated method stub
		return goodInfoDao.updateGoodInfo(goodInfo);
	}

	public Integer queryGoodInfoIdIdByStaffId(String staffId) {
		// TODO Auto-generated method stub
		return goodInfoDao.queryGoodInfoIdIdByStaffId(staffId);
	}

	public Integer deleteGoodAdmin(String staffId) {
		// TODO Auto-generated method stub
		return goodInfoDao.deleteGoodAdminInfo(staffId);
	}
}
